<?php

namespace iBrand\Component\Discount\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;

class SingleDiscount extends Model implements Transformable
{
	use TransformableTrait;

	protected $table   = 'el_single_discount';
	protected $guarded = ['id'];

	public function conditions()
	{
		return $this->hasMany(SingleDiscountCondition::class, 'single_discount_id');
	}

	public function getStatusTextAttribute()
	{
		if ($this->status == 1 AND $this->ends_at > Carbon::now()) {
			return '有效';
		} else {
			return '无效';
		}
	}

	public function getStatusFlagAttribute()
	{
		if ($this->status == 1 AND $this->ends_at > Carbon::now()) {
			return 1;
		} else {
			return 0;
		}
	}

}
